package cn.com.wdjedu.androidapp.wjeduandroid.ui.baseui;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;

import cn.com.wdjedu.androidapp.wjeduandroid.R;
import cn.com.wdjedu.androidapp.wjeduandroid.support.lib.global.GlobalContext;

/**
 * 提供方法注入fragment
 */

public abstract class AbstractInjectFragmentActivity extends AbstractAppActivity {
    public AbstractAppFragment appFragment;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_base);
        FragmentManager fm = getSupportFragmentManager();
        appFragment = (AbstractAppFragment) fm.findFragmentByTag(this.getClass().getName());
        if (appFragment == null) {
            appFragment = initFragment();
            GlobalContext.getInstance().setContentByFragment(getSupportFragmentManager(),
                    R.id.container_activity_base, appFragment, this.getClass().getName());
        }
    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    /**
     * 初始化fragment
     *
     * @return
     */
    protected abstract AbstractAppFragment initFragment();

}
